package com.yuexunit.mobilenurse.module.BloodManage.ui;

import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yuexunit.mobilenurse.R;
import com.yuexunit.mobilenurse.config.AppConfig;
import com.yuexunit.mobilenurse.widget.ActionSheetDialog;
import com.yuexunit.mobilenurse.widget.LoginDialog;

import org.kymjs.kjframe.KJActivity;
import org.kymjs.kjframe.utils.PreferenceHelper;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by chenss on 2017/9/11 0011.
 */

public class Act_Blood_Execute extends KJActivity {

    @Bind(R.id.title_tv)
    TextView titleTv;
    @Bind(R.id.tv_name)
    TextView tvName;
    @Bind(R.id.tv_hos_num)
    TextView tvHosNum;
    @Bind(R.id.tv_bed_num)
    TextView tvBedNum;
    @Bind(R.id.ll_hos_num)
    LinearLayout llHosNum;
    @Bind(R.id.tv_blood_num)
    TextView tvBloodNum;
    @Bind(R.id.ll_blood_num)
    LinearLayout llBloodNum;
    @Bind(R.id.tv_bag_num)
    TextView tvBagNum;
    @Bind(R.id.bag_state)
    TextView bagState;
    @Bind(R.id.ll_bag_num)
    LinearLayout llBagNum;
    @Bind(R.id.blood_type)
    TextView bloodType;
    @Bind(R.id.tv_blood_amount)
    TextView tvBloodAmount;
    @Bind(R.id.rl_blood_1)
    RelativeLayout rlBlood1;
    @Bind(R.id.tv_bad_content)
    TextView tvBadContent;
    @Bind(R.id.ll_bad_content)
    LinearLayout llBadContent;
    @Bind(R.id.tv_bag_num_2)
    TextView tvBagNum2;
    @Bind(R.id.bag_state_2)
    TextView bagState2;
    @Bind(R.id.blood_type_2)
    TextView bloodType2;
    @Bind(R.id.tv_blood_amount_2)
    TextView tvBloodAmount2;
    @Bind(R.id.tv_bad_content_2)
    TextView tvBadContent2;
    @Bind(R.id.check_person)
    TextView checkPerson;
    @Bind(R.id.check_idea)
    TextView checkIdea;
    @Bind(R.id.tv_doc_share_set)
    TextView tvDocShareSet;

    LoginDialog loginDialog;

    @Override
    public void setRootView() {
        setContentView(R.layout.act_blood_execute);
        ButterKnife.bind(this);
    }

    @OnClick({R.id.back, R.id.execute, R.id.tv_check_person, R.id.tv_check_idea})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back:
                break;
            case R.id.execute:
                break;
            case R.id.tv_check_person:
                loginDialog = new LoginDialog(aty).builder();
                loginDialog.setCallBack(new LoginDialog.ICallBack() {
                    @Override
                    public void callback(Bundle bundle) {
                        if(bundle != null){
                            if(bundle.getString("auditSave").equals("1")){
                                String filename = AppConfig.HISUSER_INFO;
                                PreferenceHelper.write(aty, filename, AppConfig.HIS_JOB_NUM, bundle.getString("person_num"));
                                PreferenceHelper.write(aty, filename, AppConfig.HIS_PSW, bundle.getString("person_psw"));
                                PreferenceHelper.write(aty, filename, AppConfig.SAVE_TIME, new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
                            }
                        }
                    }
                });
                String time = PreferenceHelper.readString(aty, AppConfig.HISUSER_INFO, AppConfig.SAVE_TIME);
                if(time != null && !time.isEmpty()){
                    if(new SimpleDateFormat("yyyy-MM-dd").format(new Date()).equals(time)){
                        loginDialog.setTxt(PreferenceHelper.readString(aty, AppConfig.HISUSER_INFO, AppConfig.HIS_JOB_NUM),
                                PreferenceHelper.readString(aty, AppConfig.HISUSER_INFO, AppConfig.HIS_PSW));
                    }
                }
                loginDialog.show();
                break;
            case R.id.tv_check_idea:
                selectIdea();
                break;
        }
    }

    private void selectIdea(){
        new ActionSheetDialog(aty)
                .builder()
                .setCancelable(false)
                .setCanceledOnTouchOutside(false)
                .addSheetItem("通过", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                checkIdea.setText("通过");
                            }
                        })
                .addSheetItem("不通过", ActionSheetDialog.SheetItemColor.Blue,
                        new ActionSheetDialog.OnSheetItemClickListener() {
                            @Override
                            public void onClick(int which) {
                                checkIdea.setText("不通过");
                            }
                        }).show();
    }
}
